﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Smart
{
    public partial class frmRapor : Form
    {
        public frmRapor()
        {
            InitializeComponent();
        }

        private void btnKapat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                using (Query q = new Query(ProgramTipleri.SqlCe))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("SELECT        evr_tutar, evr_isk1_tutar, evr_isk2_tutar, evr_isk3_tutar, evr_isk4_tutar, evr_isk5_tutar, evr_isk6_tutar, evr_vergi_tutar ");
                    sb.Append(" FROM            TBL_EVRAK ");
                    sb.Append(" WHERE        (evr_tarih >= @baslangic AND evr_tarih <= @bitis)");
                    q.Add(sb.ToString());
                    q.Add("@baslangic", SqlDbType.DateTime, new DateTime(dteBaslangic.Value.Year, dteBaslangic.Value.Month, dteBaslangic.Value.Day));
                    q.Add("@bitis", SqlDbType.DateTime, new DateTime(dteBitis.Value.Year, dteBitis.Value.Month, dteBitis.Value.Day, 23, 59, 59));

                    var sonuc = q.ToList(new { tutar = 0m, isk1 = 0m, isk2 = 0m, isk3 = 0m, isk4 = 0m, isk5 = 0m, isk6 = 0m, vergi = 0m }).FirstOrDefault();
                    if (sonuc != null)
                    {
                        txtBrtSatis.Text = sonuc.tutar.ToString("n2");
                        txtIskonto.Text = (sonuc.isk1 + sonuc.isk2 + sonuc.isk3).ToString("n2");
                        txtNetSatis.Text = (sonuc.tutar - (sonuc.isk1 + sonuc.isk2 + sonuc.isk3)).ToString("n2");
                        txtKdvToplam.Text = sonuc.vergi.ToString("n2");
                        txtKdvDahilToplamSatis.Text = ((sonuc.tutar - (sonuc.isk1 + sonuc.isk2 + sonuc.isk3)) + sonuc.vergi).ToString("n2");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandling.Hand(ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void frmRapor_Load(object sender, EventArgs e)
        {
            dteBaslangic.Value = DateTime.Now;
            dteBitis.Value = DateTime.Now;
        }
    }
}